<!DOCTYPE html>
<html>
<head>
    <head/>
    <title>预约详情</title>
    <%- include('./_global/baseLibs') %>

    <style type="text/css">
        .yyxq-box .last-btn-box .btn-left{
            width: 48% !important;
            margin-left: 4%;
        }
    </style>
</head>


<body>
<section class="page-wrap yyxq-box yyxx-box">
    <header class="header-box grey fixed">
        <div class="header-content">
            <div class="left-tool">
                <a class="back" href="javascript:void(0);"><i class="iconfont icon-back"></i></a>
            </div>
            <div class="title">预约详情</div>
        </div>
    </header>
    <div class="first-box">
        <span class="first-text orderInfo" name="orderStatus"></span>
        <span class="orderInfo" name="orderInfo"></span>
    </div>
    <div class="second-box">
        <div class="yy-message">
            <span class="title-text">预约信息</span>
            <p><span class="text-left">就诊医院：</span><span class="orderInfo" name="hosName"></span></p>
            <p><span class="text-left">就诊科室：</span><span class="orderInfo" name="depName"></span></p>
            <p><span class="text-left">就诊医生：</span><span class="orderInfo" name="docName"></span></p>
            <p><span class="text-left">就诊时间：</span><span class="orderInfo" name="scheduleDate"></span></p>
            <!-- <p><span class="text-left">候诊地点：</span><span class="orderInfo" name="position"></span></p> -->
            <p><span class="text-left">门诊类型：</span><span class="orderInfo" name="mzType"></span></p>
        </div>
        <!-- <a class="ck-map" href="javascript:void(0);">查看地图</a> -->
        <a class="fk-text orderInfo" name="">在线支付</a>
    </div>
    <div class="third-box">
        <div class="person-message">
            <span class="title-text">就诊人信息</span>
            <p><span class="text-left">就诊人：</span><span class="orderInfo" name="patientName"> </span></p>
            <p><span class="text-left">身份证号：</span><span class="orderInfo" name="patientCardId"></span></p>
            <p><span class="text-left">手机号：</span><span class="orderInfo" name="patientPhone"></span></p>
        </div>
    </div>
    <div class="forth-box">
        <div class="remind-box">
            <span class="title-text">温馨提示</span>
            <span class="orderInfo" name="qxsj"></span>
            <span>在就诊前医生若停诊医院会短信通知</span>
            <span  class="orderInfo" name="lxdh"></span>
        </div>
    </div>
    <div class="last-btn-box">
        <!-- <a class="btn-left" href="javascript:void(0);">再次预约</a>
        <a class="btn-right" href="javascript:void(0);">立即评价</a> -->
    </div>
</section>

</body>
<script type="text/html" id="cgBtn">
    <a class="btn-single" id="topay" href="javascript:void(0);" >立即支付</a>
    <a class="btn-left reservationAgain" href="javascript:void(0);" >再次预约</a>
    <!-- <a class="btn-right" href="javascript:void(0);" onclick="qxyy('#orderId#')">取消预约</a> -->
    <a class="btn-right qxyy" href="javascript:void(0);" >取消预约</a>
</script>
<script type="text/html" id="qxBtn">
    <a class="btn-left reservationAgain" href="javascript:void(0);" >再次预约</a>
</script>
<script type="text/html" id="jzBtn">
    <a class="btn-left reservationAgain" href="javascript:void(0);" >再次预约</a>
    <a class="btn-right" href="javascript:void(0);"  >立即评价</a>
</script>
<script src="/static/lib/forweb.js"></script>
<script src="/quickJs/scripts/swiper/3.4.2/js/swiper.min.js"></script>
<!-- start支付引用。需传入支付成功后跳转的url.还有擦掉按钮之后的行为。需要调用toGetPay 传入获取订单相关信息的参数 -->
<!-- <%- include('./_global/toPay.ejs') %> -->

<!-- end -->
<script type="text/javascript">
    var requestRoot = "/gzd/yygh/";



    /**取消预约*/
    function qxyy(result){
        /**取消预约*/
        $.QuickAlert.alertConfirm({content: "确认是否退号?",title: "系统提示",callback: function(){
            // var data = StoreCache.getCache("yyInfo");
            var params = {
                orderId:result.orderId,
                hosOrgCode:result.hosCode,
                platformUserId:result.platformUserId
            }
            $.QuickRemote.AjaxJson({
                funcName:"/api"+requestRoot + "cancelReservation"
                ,callback:function(result){
                    $.QuickAlert.alertNormal("取消预约成功！",{callback: function(){
                        /**刷新当前页面*/
                        location.reload();

                    }});
                },params:params
            });
        }});
    }

    var page_yyDetail = (function($, page_yyDetail) {

        /**加载视图*/
        function initMapHandler(hosInfo){
            /**查看地图*/
            $(".ck-map").on("click",function(){
                var str =  hosInfo["hosLocation"];
                if(str) {
                    var strs = str.split(",");
                    var params = {
                        longitude: strs[0],
                        latitude: strs[1],
                        hosName: hosInfo["hosName"]
                    };
                    $.JkcsUtils.gotoMap(params);
                }
            });
        }
        /**加载数据*/
        function initData(){
            /**获取预约单编号*/
            /*YYGH_HYCGINFO*/
             var yyCginfo = StoreCache.getCache("YYGH_YYCGINFO");

            var params ={
                hosCode:yyCginfo["hosOrgCode"],
                orderId :yyCginfo["orderId "]
            }
            $.QuickRemote.AjaxJson({
                funcName:"/api"+requestRoot + "getOrderDetail"
                ,callback:function(data) {
                    /**获取预约信息*/
                    /**预约单信息赋值*/
                    data = page_yyDetail.getOrderInfo(data);
                    $("body").find(".orderInfo").each(function(){
                        if($(this).attr("name")=="orderStatus"){
                            $(this).text(page_yyDetail.getStatus(data.orderStatus));
                        }else{
                            $(this).text(data[$(this).attr("name")]);
                        }
                    });

                }
                ,params:params
            });
        }
        /**获取并转换预约信息 */
        function getStatus(orderStatus){
            if(orderStatus=="1"){
                orderStatus = "已预约";
            }else if(orderStatus=="2"){
                orderStatus = "已支付";
            }else if(orderStatus=="3"){
                orderStatus = "已退号";
            }else if(orderStatus=="4"){
                orderStatus = "已取号";
            }else if(orderStatus=="5"){
                orderStatus = "待退费";
            }
            return orderStatus;
        }
        /**获取并转换预约信息 */
        function getOrderInfo(data){
            $('body').data('orderDetail', data);
            page_yyDetail.initMapHandler(data);
            var orderStatus = data["orderStatus"];
            var btn;
            if(orderStatus == "1"){
                btn = $($("#cgBtn").html().replace("#orderId#",data["orderId"]));
                data["orderStatus"] = "预约成功！请按时就诊！";
                data["orderInfo"] = "请在"+data["scheduleDate"]+"按时到医院取号就诊";
            }
            else if(orderStatus == "2"){
                btn = $($("#jzBtn").html());
                data["orderStatus"] = "已支付！";
                data["orderInfo"] = "请及时就诊";
            }
            else if(orderStatus == "3"){
                btn = $($("#qxBtn").html());
                data["orderStatus"] = "已退号";
                data["orderInfo"] = "您的预约单已取消。";
            }
            else if(orderStatus == "4"){
                btn = $($("#qxBtn").html());
                data["orderStatus"] = "已取号！";
                data["orderInfo"] = "请及时就诊";
            }else if(orderStatus == "5"){
                btn = $($("#qxBtn").html());
                data["orderStatus"] = "待退费！";
                data["orderInfo"] = "已退号，待退费！";
            }
            /**添加按钮*/
            $(".last-btn-box").append(btn);
            /*if(orderStatus == "1"){
                $("#topay").data("payInfo",data);
                $("#topay").click(function(){
                    $('.pay-list-box').show();
                });*/
                $(".qxyy").attr("onclick","qxyy("+JSON.stringify(data)+")")
            }
            data["jzsj"] = data["scheduleDate"] +" "+ page_yyDetail.getWeek(data["scheduleDate"]) +" "+ data["timeRange"];
            var value = data["visitCost"];
            if(StringUtils.isEmpty(value)){
                value = "0";
            }
            data["lxdh"] = " 如需帮助，请拨打客服电话：" + value;
            data["mzType"] = page_yyDetail.getRegType(data["regType"]) + value + "元";
            data["qxsj"] = page_yyDetail.getQxsj(data["scheduleDate"]);
            var patientCardId = data["patientCardId"];
            data["kh"] = patientCardId;
            data["patientCardId"] = patientCardId.substr(0,3) + "******" + patientCardId.substr(patientCardId.length-4,patientCardId.length);
            var patientPhone = data["patientPhone"];
            data["patientPhone"] = patientPhone.substr(0,3) + "******" + patientPhone.substr(patientPhone.length-4,patientPhone.length);
            return data;
        }
        /**根据日期获取week*/
        function getWeek(dateString){
            var dateArray = dateString.split("-");
            var date = new Date(dateArray[0], parseInt(dateArray[1] - 1), dateArray[2]);
            return "周" + "日一二三四五六".charAt(date.getDay());
        }

        /**获取取消时间*/
        function getQxsj(qxsj){
            var translateDate = "", dateString = "", monthString = "", dayString = "";
            translateDate = qxsj.replace("-", "/").replace("-", "/");
            var newDate = new Date(translateDate);
            newDate = newDate.valueOf();
            newDate = newDate - 1 * 24 * 60 * 60 * 1000;
            newDate = new Date(newDate);
            //如果月份长度少于2，则前加 0 补位
            if ((newDate.getMonth() + 1).toString().length == 1) {
                monthString = 0 + "" + (newDate.getMonth() + 1).toString();
            } else {
                monthString = (newDate.getMonth() + 1).toString();
            }
            //如果天数长度少于2，则前加 0 补位
            if (newDate.getDate().toString().length == 1) {
                dayString = 0 + "" + newDate.getDate().toString();
            } else {
                dayString = newDate.getDate().toString();
            }
            dateString = newDate.getFullYear() + "-" + monthString + "-" + dayString;
            return "取消预约截止时间为"+dateString;
        }

        /**获取门诊类型*/
        function getRegType(regType){
            var value = "";
            if(regType == "100"){
                value = "普通门诊";
            }
            else if(regType == "101"){
                value = "专科门诊";
            }
            else if(regType == "102"){
                value = "专家门诊";
            }
            else if(regType == "103"){
                value = "特需门诊";
            }
            else if(regType == "104"){
                value = "专病门诊";
            }
            else if(regType == "999"){
                value = "其它门诊";
            }
            return value;
        }

        /**再次预约*/
        function zcyy(){
            var orderDetail = $('body').data('orderDetail');
            $.pageSwitch.goToUrl("myOrder", "hosDetail", 'hosCode=' + orderDetail['hosCode']);
        }

        /**立即评价*/
        function ljpj(){
            
            // $.QuickUrlUtils.redirectJSBridge({url: "",title: "评价"});
            $.pageSwitch.goToUrl("estimate", "jzpj");
        }

        var cfg_def = {
            initData: initData,
            initMapHandler: initMapHandler,
            getStatus: getStatus,
            getOrderInfo: getOrderInfo,
            getWeek: getWeek,
            getQxsj: getQxsj,
            getRegType: getRegType,
            zcyy: zcyy,
            ljpj: ljpj,
        }

        page_yyDetail.init = function(cfg){
            $.extend(page_yyDetail, cfg_def, cfg);
            page_yyDetail.initData();
            //successUrl表示支付成功后跳转的url.closeUrl表示支付窗口点击关闭按钮后跳转的url。为空则表示只擦掉当前支付窗口
          //  $(".pay-btn").attr("urlInfo",JSON.stringify({successUrl:$.getUrl.pageUrl("myOrder","wdyy"),closeUrl:"",animate:"pop"}));
            //$(".reservationAgain").click(page_yyDetail.zcyy);
           
            //$("#jzBtn .btn-right").click(page_yyDetail.ljpj);
             $("#jzBtn").find(".btn-right").on('click', page_yyDetail.ljpj());//

           /* $(".pay-btn").click(function(){
                var info =$("#topay").data("payInfo");
                var parmas={
                    "yljgdm":info.hosCode,
                    "order_id":info.orderId,
                    "schedule_id":info.scheduleCode,
                    "je":info.visitCost,
                    "klx":"01",
                    "kh":info.kh
                }
                toGetPay(parmas);
            })*/
        }


        return page_yyDetail;
    })(jQuery, {});
    
    

</script>
</html>